package ModelLayer;
import java.util.ArrayList;

/**
 * Vestbjerg project
 * @GroupB2 (UCN - Computer Science DMAJ0914) 
 */

public class MachineryContainer
{
    // instance variables
    private static MachineryContainer instance;
    private ArrayList<Machinery> machineryList;

    /**
     * Constructor for objects of class ProductContainer
     */
    public MachineryContainer()
    {
        machineryList = new ArrayList<Machinery>();
    }

    public static MachineryContainer getInstance()
    {
        if(instance == null)
        {
            instance = new MachineryContainer();
        }
        return instance;
    }

    public void addMachinery(Machinery machinery)
    {
        machineryList.add(machinery);
    }

    public Machinery findMachinery(String barcode)
    {
        Machinery returnMachinery = null;
        for(Machinery machinery : machineryList) 
        {

            if(barcode.equals(machinery.getBarcode())) 
            {
                returnMachinery = machinery;
            }
        }
        return returnMachinery;
    }

    public void deleteMachinery(Machinery machinery)
    {
        if(machineryList.contains(machinery))
        {
            machineryList.remove(machinery);
        }
    }

    public Unit findUnit(String serialNumber) 
    {
        Unit returnUnit = null;
        for(Machinery machinery : machineryList) 
        {
            for(Unit unit : machinery.getUnitList()) 
            {
                if(unit.getSerialNumber().equals(serialNumber))
                {
                    returnUnit = unit;
                }
            }
        }
        return returnUnit;
    }

    public ArrayList<Machinery> getMachineryList() 
    {
        return machineryList;
    }
}
